package com.android.demo;

import android.app.ActivityGroup;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.SeekBar;

public class TestProgressBar extends ActivityGroup {
	LinearLayout frameMain;
	private String TAG = "TestProgressBar";
	private SeekBar mSB;
	private  ProgressBar mPB;
	private LinearLayout mL;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.progress_bar);
		
		
		mSB = (SeekBar)findViewById(R.id.seek_bar);
		mL = (LinearLayout)findViewById(R.id.stars_bar);
		
		mL.setOnTouchListener(new OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				
				ViewGroup.LayoutParams lp = mL.getLayoutParams();
				if (lp!=null) {
					int currentX = (int)event.getX();
					int total = mL.getWidth();
					currentX = currentX>total?total:currentX; 
					int process = currentX*10/total;
					
					int star = 0;
					switch (process){
					case 0:
						star = 0;
						break;
					case 1:
					case 2:
						star = 1;
						break;
					case 3:
					case 4:
						star = 2;
						break;
					case 5:
					case 6:
						star = 3;
						break;
					case 7:
					case 8:
						star = 4;
						break;
					case 9:
					case 10:
						star = 5;
						break;
					}
					
					for (int j=0; j<mL.getChildCount(); j++) {
						ImageView btn = (ImageView)mL.getChildAt(j);
						btn.setImageResource(star>j?R.drawable.btn_star_big_active:R.drawable.btn_star_big_default);
					}
				}
				return true;
			}
		});
	}
	
	
}